/******************************************************************************
 * Copyright 2023 The Apollo Authors. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *****************************************************************************/

#include "modules/canbus_vehicle/x3epro/protocol/scu_frontwheelspeed_301.h"
#include "glog/logging.h"
#include "modules/drivers/canbus/common/byte.h"
#include "modules/drivers/canbus/common/canbus_consts.h"

namespace apollo {
namespace canbus {
namespace x3epro {

using ::apollo::drivers::canbus::Byte;

Scufrontwheelspeed301::Scufrontwheelspeed301() {}
const int32_t Scufrontwheelspeed301::ID = 0x301;

void Scufrontwheelspeed301::Parse(const std::uint8_t* bytes, int32_t length,
                         X3epro* chassis) const {
  chassis->mutable_scu_frontwheelspeed_301()->set_vehiclerealdirect(vehiclerealdirect(bytes, length));
  chassis->mutable_scu_frontwheelspeed_301()->set_avas_switch(avas_switch(bytes, length));
  chassis->mutable_scu_frontwheelspeed_301()->set_vehiclespeed(vehiclespeed(bytes, length));
  chassis->mutable_scu_frontwheelspeed_301()->set_wheelspeed_fl_valid(wheelspeed_fl_valid(bytes, length));
  chassis->mutable_scu_frontwheelspeed_301()->set_wheelspeed_fl(wheelspeed_fl(bytes, length));
  chassis->mutable_scu_frontwheelspeed_301()->set_wheelspeed_fr_valid(wheelspeed_fr_valid(bytes, length));
  chassis->mutable_scu_frontwheelspeed_301()->set_wheelspeed_fr(wheelspeed_fr(bytes, length));
  chassis->mutable_scu_frontwheelspeed_301()->set_alivecounter_front(alivecounter_front(bytes, length));
  chassis->mutable_scu_frontwheelspeed_301()->set_wheelspeed_fl_direct(wheelspeed_fl_direct(bytes, length));
  chassis->mutable_scu_frontwheelspeed_301()->set_wheelspeed_fr_direct(wheelspeed_fr_direct(bytes, length));
  chassis->mutable_scu_frontwheelspeed_301()->set_checksum_front(checksum_front(bytes, length));
}

// config detail: {'bit': 6, 'enum': {0: 'VEHICLEREALDIRECT_N', 1: 'VEHICLEREALDIRECT_D', 2: 'VEHICLEREALDIRECT_R'}, 'is_signed_var': False, 'len': 2, 'name': 'vehiclerealdirect', 'offset': 0.0, 'order': 'motorola', 'physical_range': '[0|0]', 'physical_unit': 'bit', 'precision': 1.0, 'type': 'enum'}
Scu_frontwheelspeed_301::VehiclerealdirectType Scufrontwheelspeed301::vehiclerealdirect(const std::uint8_t* bytes, int32_t length) const {
  Byte t0(bytes + 0);
  int32_t x = t0.get_byte(5, 2);

  Scu_frontwheelspeed_301::VehiclerealdirectType ret =  static_cast<Scu_frontwheelspeed_301::VehiclerealdirectType>(x);
  return ret;
}

// config detail: {'bit': 7, 'enum': {0: 'AVAS_SWITCH_OFF', 1: 'AVAS_SWITCH_ON'}, 'is_signed_var': False, 'len': 1, 'name': 'avas_switch', 'offset': 0.0, 'order': 'motorola', 'physical_range': '[0|0]', 'physical_unit': 'bit', 'precision': 1.0, 'type': 'enum'}
Scu_frontwheelspeed_301::Avas_switchType Scufrontwheelspeed301::avas_switch(const std::uint8_t* bytes, int32_t length) const {
  Byte t0(bytes + 0);
  int32_t x = t0.get_byte(7, 1);

  Scu_frontwheelspeed_301::Avas_switchType ret =  static_cast<Scu_frontwheelspeed_301::Avas_switchType>(x);
  return ret;
}

// config detail: {'bit': 4, 'is_signed_var': False, 'len': 13, 'name': 'vehiclespeed', 'offset': 0.0, 'order': 'motorola', 'physical_range': '[0|0]', 'physical_unit': 'Km/h ->  m/s', 'precision': 0.05625, 'type': 'double'}
double Scufrontwheelspeed301::vehiclespeed(const std::uint8_t* bytes, int32_t length) const {
  Byte t0(bytes + 0);
  int32_t x = t0.get_byte(0, 5);

  Byte t1(bytes + 1);
  int32_t t = t1.get_byte(0, 8);
  x <<= 8;
  x |= t;

  double ret = x * 0.056250 / 3.6;
  return ret;
}

// config detail: {'bit': 23, 'enum': {0: 'WHEELSPEED_FL_INVALID', 1: 'WHEELSPEED_FL_VALID'}, 'is_signed_var': False, 'len': 1, 'name': 'wheelspeed_fl_valid', 'offset': 0.0, 'order': 'motorola', 'physical_range': '[0|0]', 'physical_unit': 'bit', 'precision': 1.0, 'type': 'enum'}
Scu_frontwheelspeed_301::Wheelspeed_fl_validType Scufrontwheelspeed301::wheelspeed_fl_valid(const std::uint8_t* bytes, int32_t length) const {
  Byte t0(bytes + 2);
  int32_t x = t0.get_byte(7, 1);

  Scu_frontwheelspeed_301::Wheelspeed_fl_validType ret =  static_cast<Scu_frontwheelspeed_301::Wheelspeed_fl_validType>(x);
  return ret;
}

// config detail: {'bit': 22, 'is_signed_var': False, 'len': 15, 'name': 'wheelspeed_fl', 'offset': 0.0, 'order': 'motorola', 'physical_range': '[0|0]', 'physical_unit': 'Km/h ->  m/s', 'precision': 0.01, 'type': 'double'}
double Scufrontwheelspeed301::wheelspeed_fl(const std::uint8_t* bytes, int32_t length) const {
  Byte t0(bytes + 2);
  int32_t x = t0.get_byte(0, 7);

  Byte t1(bytes + 3);
  int32_t t = t1.get_byte(0, 8);
  x <<= 8;
  x |= t;

  double ret = x * 0.010000 / 3.6;
  return ret;
}

// config detail: {'bit': 39, 'enum': {0: 'WHEELSPEED_FR_INVALID', 1: 'WHEELSPEED_FR_VALID'}, 'is_signed_var': False, 'len': 1, 'name': 'wheelspeed_fr_valid', 'offset': 0.0, 'order': 'motorola', 'physical_range': '[0|0]', 'physical_unit': 'bit', 'precision': 1.0, 'type': 'enum'}
Scu_frontwheelspeed_301::Wheelspeed_fr_validType Scufrontwheelspeed301::wheelspeed_fr_valid(const std::uint8_t* bytes, int32_t length) const {
  Byte t0(bytes + 4);
  int32_t x = t0.get_byte(7, 1);

  Scu_frontwheelspeed_301::Wheelspeed_fr_validType ret =  static_cast<Scu_frontwheelspeed_301::Wheelspeed_fr_validType>(x);
  return ret;
}

// config detail: {'bit': 38, 'is_signed_var': False, 'len': 15, 'name': 'wheelspeed_fr', 'offset': 0.0, 'order': 'motorola', 'physical_range': '[0|0]', 'physical_unit': 'Km/h ->  m/s', 'precision': 0.01, 'type': 'double'}
double Scufrontwheelspeed301::wheelspeed_fr(const std::uint8_t* bytes, int32_t length) const {
  Byte t0(bytes + 4);
  int32_t x = t0.get_byte(0, 7);

  Byte t1(bytes + 5);
  int32_t t = t1.get_byte(0, 8);
  x <<= 8;
  x |= t;

  double ret = x * 0.010000 / 3.6;
  return ret;
}

// config detail: {'bit': 51, 'is_signed_var': False, 'len': 4, 'name': 'alivecounter_front', 'offset': 0.0, 'order': 'motorola', 'physical_range': '[0|0]', 'physical_unit': '', 'precision': 1.0, 'type': 'int'}
int Scufrontwheelspeed301::alivecounter_front(const std::uint8_t* bytes, int32_t length) const {
  Byte t0(bytes + 6);
  int32_t x = t0.get_byte(0, 4);

  int ret = x;
  return ret;
}

// config detail: {'bit': 53, 'enum': {0: 'WHEELSPEED_FL_DIRECT_INVALID', 1: 'WHEELSPEED_FL_DIRECT_D', 2: 'WHEELSPEED_FL_DIRECT_N', 3: 'WHEELSPEED_FL_DIRECT_R'}, 'is_signed_var': False, 'len': 2, 'name': 'wheelspeed_fl_direct', 'offset': 0.0, 'order': 'motorola', 'physical_range': '[0|0]', 'physical_unit': 'bit', 'precision': 1.0, 'type': 'enum'}
Wheelspeed_directType Scufrontwheelspeed301::wheelspeed_fl_direct(const std::uint8_t* bytes, int32_t length) const {
  Byte t0(bytes + 6);
  int32_t x = t0.get_byte(4, 2);

  Wheelspeed_directType ret =  static_cast<Wheelspeed_directType>(x);
  return ret;
}

// config detail: {'bit': 55, 'enum': {0: 'WHEELSPEED_FR_DIRECT_INVALID', 1: 'WHEELSPEED_FR_DIRECT_D', 2: 'WHEELSPEED_FR_DIRECT_N', 3: 'WHEELSPEED_FR_DIRECT_R'}, 'is_signed_var': False, 'len': 2, 'name': 'wheelspeed_fr_direct', 'offset': 0.0, 'order': 'motorola', 'physical_range': '[0|0]', 'physical_unit': 'bit', 'precision': 1.0, 'type': 'enum'}
Wheelspeed_directType Scufrontwheelspeed301::wheelspeed_fr_direct(const std::uint8_t* bytes, int32_t length) const {
  Byte t0(bytes + 6);
  int32_t x = t0.get_byte(6, 2);

  Wheelspeed_directType ret =  static_cast<Wheelspeed_directType>(x);
  return ret;
}

// config detail: {'bit': 63, 'is_signed_var': False, 'len': 8, 'name': 'checksum_front', 'offset': 0.0, 'order': 'motorola', 'physical_range': '[0|0]', 'physical_unit': '', 'precision': 1.0, 'type': 'int'}
int Scufrontwheelspeed301::checksum_front(const std::uint8_t* bytes, int32_t length) const {
  Byte t0(bytes + 7);
  int32_t x = t0.get_byte(0, 8);

  int ret = x;
  return ret;
}
}  // namespace x3epro
}  // namespace canbus
}  // namespace apollo
